%!TEX program = pdflatex
\documentclass[11pt,en]{elegantpaper}

\title{The Report for Programming Assignments in Chapter Two}
\author{Wenchong Huang}

\date{\today}

% cmd for this doc
\usepackage{array}
\usepackage{float}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{subfigure}
\newcommand{\ccr}[1]{\makecell{{\color{#1}\rule{1cm}{1cm}}}}

\begin{document}

\maketitle


\section{How to Test}

Enter the folder \verb|Programming-Chapter2/src| with terminal, \verb |make| here, you will see some executable files whose names are corresponding assignments. Run them directly and you will see the results.

\section{Mannual}

This package is for Newton's polynomial interpolation.

\subsection{Newton's Interpolation}

You should include the header \verb|interpolation.h|. Then you should give your interpolating points and interpolating values with two \verb|std::vector<double>|. Here is an example where $x_k=-5+10\frac{k}{n}\;(k=0,1,...,n)$ and $f(x)=\frac{1}{1+x^2}$.

\begin{lstlisting}
  class F{
  public:
      double operator () (const double &x) const{
          return 1.0 / (1.0 + x * x);
      }
  } func;
  std::vector<double> x, f;
  for(int i = 0; i <= n; i++){
      x.push_back(-5.0 + 10.0 * i / n);
      f.push_back(func(x[i]));
  }
\end{lstlisting}

After that, you can get the interpolation polynomial by:

\begin{lstlisting}
  NewtonInterpolation poly(x, f);
\end{lstlisting}

You can use the following code to get the value of $p_n(f;x)$ at point $x$.

\begin{lstlisting}
  double v = poly(x);
\end{lstlisting}

One of the advantage of Newton's interpolation is that it can add interpolating points conviniently. In this package, you can add one with the following code.

\begin{lstlisting}
  poly.addPoint(x_new);
\end{lstlisting}

It will increse the order of the polynomial \verb|poly| by one to make it coincides with $f$ at $x_{\text{new}}$ in an $O(n)$ time.

\subsection{Hermite's Interpolation}

Hermite's Interpolation depends not only on function values, but also deriviate values, even high-order deriviate values.

You should include the header \verb|interpolation.h|. Give your interpolating points and corresponding function values and deriviate values with two \verb|std::vector<double>|. Here is an example.

\begin{lstlisting}
  const int n = 6;
  const double xvalues[] = {0, 3, 3, 3, 5, 5};
  const double fvalues[] = {0, 225, 77, 3, 383, 80};
  std::vector<double> x(xvalues, xvalues + n);
  std::vector<double> f(fvalues, fvalues + n);
  HermiteInterpolation hpoly(x, f);
\end{lstlisting}

The code below solves the interpolation which satisfies:
\begin{equation*}
  f(0)=0,\quad f(3)=225,\quad f'(3)=77,\quad f''(3)=3,\quad f(5)=383, \quad f'(5)=80
\end{equation*}

You can get the value of the interpolation polynomial at point $x$ with the following code.

\begin{lstlisting}
  double v = poly(x);
\end{lstlisting}

\subsection{Output}

This package supports three output modes: Normal, Latex and Tikz.

The Normal mode is for human to read directly, as following

\begin{lstlisting}
  2+0.1*(x+5)-0.03*(x+5)*x
\end{lstlisting}

The Latex mode is for showing the result as a formula in a \LaTeX document, as following

\begin{lstlisting}
  2+0.1\pi_{1}(x)-0.03\pi_{2}(x)
\end{lstlisting}

The Tikz mode is for drawing the image of the result in the \textbf{Tikz} package, as following

\begin{lstlisting}
  2+0.1*(\x+5)-0.03*(\x+5)*\x
\end{lstlisting}

Use standard IO stream to output.

\begin{lstlisting}
  std::cout << poly << std::endl;
\end{lstlisting}

The default output mode is Normal. To change it, use one of the following codes.

\begin{lstlisting}
  NewtonPolynomial::setOutput(NewtonPolynomial::OUTPUT_NORMAL);
  NewtonPolynomial::setOutput(NewtonPolynomial::OUTPUT_LATEX);
  NewtonPolynomial::setOutput(NewtonPolynomial::OUTPUT_TIKZ);
\end{lstlisting}

\subsection{Canonical Polynomials}

We provided a standard polynomial class \verb|Polynomial|. To turn a polynomial of Newton's form to the canonical form, using the following code, where \verb|poly| is an object of \verb|NewtonPolynomial| or its derived classes.

\begin{lstlisting}
  Polynomial p = poly.standardize();
\end{lstlisting}

Get the deriviate function of a standard polynomial with the following code.

\begin{lstlisting}
  Polynomial dp = p.diff();
\end{lstlisting}

The point value and output of standard polynomial are the same as \verb|NewtonPolynomial|. A little difference is that the Normal mode and the Latex mode are merged to one, and looks more beautiful, as following.

\begin{lstlisting}
  10+75x+7.16191x^{2}-10.0953x^{3}
\end{lstlisting}

To change the output mode, use one of the following codes.

\begin{lstlisting}
  Polynomial::setOutput(Polynomial::OUTPUT_LATEX);
  Polynomial::setOutput(Polynomial::OUTPUT_TIKZ);
\end{lstlisting}

\section{Results}

\subsection{Assignment B}

Here are the Newton's interpolation results.
\begin{align*}
  p_2(f;x) &= 0.0384615+0.192308\pi_{1}(x)-0.0384615\pi_{2}(x)\\
  p_4(f;x) &= 0.0384615+0.0397878\pi_{1}(x)+0.061008\pi_{2}(x)-0.0265252\pi_{3}(x)+0.00530504\pi_{4}(x)\\
  p_6(f;x) &= 0.0384615+0.0264644\pi_{1}(x)+0.0248454\pi_{2}(x)+0.0149446\pi_{3}(x)-0.0131699\pi_{4}(x)\\
           &  +0.00420316\pi_{5}(x)-0.000840633\pi_{6}(x)\\
  p_8(f;x) &= 0.0384615+0.0223428\pi_{1}(x)+0.013956\pi_{2}(x)+0.0117043\pi_{3}(x)+0.000674338\pi_{4}(x)\\
           &  -0.00489646\pi_{5}(x)+0.00243964\pi_{6}(x)-0.000687223\pi_{7}(x)+0.000137445\pi_{8}(x)
\end{align*}

The following figure shows the images of the interpolating polynomials and the original function.

\tikzset{global scale/.style={
    scale=#1,
    every node/.append style={scale=#1}
  }
}

\begin{center}
  \begin{tikzpicture}[global scale = 0.8]
    \begin{axis}[
        axis lines=middle,
        samples=51,
  %       grid,                
  %      thick,
        domain=-5:5,
        legend pos=outer north east,
        smooth,
    ]
    \addplot+[color=red!80!black!20,no marks]{0.0384615+0.192308*(\x+5)-0.0384615*(\x+5)*\x};
    \addplot+[color=red!60!black!40,no marks]{0.0384615+0.0397878*(\x+5)+0.061008*(\x+5)*(\x+2.5)-0.0265252*(\x+5)*(\x+2.5)*\x+0.00530504*(\x+5)*(\x+2.5)*\x*(\x-2.5)};
    \addplot+[color=red!40!black!60,no marks]{0.0384615+0.0264644*(\x+5)+0.0248454*(\x+5)*(\x+3.33333)+0.0149446*(\x+5)*(\x+3.33333)*(\x+1.66667)-0.0131699*(\x+5)*(\x+3.33333)*(\x+1.66667)*\x+0.00420316*(\x+5)*(\x+3.33333)*(\x+1.66667)*\x*(\x-1.66667)-0.000840633*(\x+5)*(\x+3.33333)*(\x+1.66667)*\x*(\x-1.66667)*(\x-3.33333)};
    \addplot+[color=red!20!black!80,no marks]{0.0384615+0.0223428*(\x+5)+0.013956*(\x+5)*(\x+3.75)+0.0117043*(\x+5)*(\x+3.75)*(\x+2.5)+0.000674338*(\x+5)*(\x+3.75)*(\x+2.5)*(\x+1.25)-0.00489646*(\x+5)*(\x+3.75)*(\x+2.5)*(\x+1.25)*\x+0.00243964*(\x+5)*(\x+3.75)*(\x+2.5)*(\x+1.25)*\x*(\x-1.25)-0.000687223*(\x+5)*(\x+3.75)*(\x+2.5)*(\x+1.25)*\x*(\x-1.25)*(\x-2.5)+0.000137445*(\x+5)*(\x+3.75)*(\x+2.5)*(\x+1.25)*\x*(\x-1.25)*(\x-2.5)*(\x-3.75)};
    \addplot+[color=black,thick,no marks]{1/(1+\x*\x)};
    \addlegendentry{$p_2(f;x)$}
    \addlegendentry{$p_4(f;x)$}
    \addlegendentry{$p_6(f;x)$}
    \addlegendentry{$p_8(f;x)$}
    \addlegendentry{$f(x)$}
    \end{axis}
  \end{tikzpicture}
\end{center}

This figure illustrates the Runge phenomenon significantly.

\subsection{Assignment C}

In this assignment, we choose the interpolating points to be the zeros of Chebyshev polynomials $T_n$, which are

\begin{equation*}
  x_k=\cos\left(\frac{2k-1}{2n}\pi\right),\qquad k=1,2,...,n
\end{equation*}

The interpolation results are too long to show. Please run the corresponding program directly to see the results. The following figure shows the images of the interpolating polynomials and the original function.

\begin{center}
  \begin{tikzpicture}[global scale = 0.8]
    \begin{axis}[
        axis lines=middle,
        samples=51,
  %       grid,                
  %      thick,
        domain=-1:1,
        legend pos=outer north east,
        smooth,
    ]
    \addplot+[color=red!80!black!20,no marks]{0.0423501-0.169057*(\x-0.951057)+1.42548*(\x-0.951057)*(\x-0.587785)+2.61208*(\x-0.951057)*(\x-0.587785)*(\x-6.12323e-17)+2.7465*(\x-0.951057)*(\x-0.587785)*(\x-6.12323e-17)*(\x+0.587785)};
    \addplot+[color=red!60!black!40,no marks]{0.0393884-0.0887389*(\x-0.987688)+0.189679*(\x-0.987688)*(\x-0.891007)-0.534305*(\x-0.987688)*(\x-0.891007)*(\x-0.707107)+2.11681*(\x-0.987688)*(\x-0.891007)*(\x-0.707107)*(\x-0.45399)+8.28743*(\x-0.987688)*(\x-0.891007)*(\x-0.707107)*(\x-0.45399)*(\x-0.156434)+11.9543*(\x-0.987688)*(\x-0.891007)*(\x-0.707107)*(\x-0.45399)*(\x-0.156434)*(\x+0.156434)+10.3568*(\x-0.987688)*(\x-0.891007)*(\x-0.707107)*(\x-0.45399)*(\x-0.156434)*(\x+0.156434)*(\x+0.45399)+5.51277*(\x-0.987688)*(\x-0.891007)*(\x-0.707107)*(\x-0.45399)*(\x-0.156434)*(\x+0.156434)*(\x+0.45399)*(\x+0.707107)+8.9925e-16*(\x-0.987688)*(\x-0.891007)*(\x-0.707107)*(\x-0.45399)*(\x-0.156434)*(\x+0.156434)*(\x+0.45399)*(\x+0.707107)*(\x+0.891007)};
    \addplot+[color=red!40!black!60,no marks]{0.0388699-0.0800675*(\x-0.994522)+0.134961*(\x-0.994522)*(\x-0.951057)-0.231498*(\x-0.994522)*(\x-0.951057)*(\x-0.866025)+0.449158*(\x-0.994522)*(\x-0.951057)*(\x-0.866025)*(\x-0.743145)-1.04753*(\x-0.994522)*(\x-0.951057)*(\x-0.866025)*(\x-0.743145)*(\x-0.587785)+2.33944*(\x-0.994522)*(\x-0.951057)*(\x-0.866025)*(\x-0.743145)*(\x-0.587785)*(\x-0.406737)+14.0283*(\x-0.994522)*(\x-0.951057)*(\x-0.866025)*(\x-0.743145)*(\x-0.587785)*(\x-0.406737)*(\x-0.207912)+6.93539*(\x-0.994522)*(\x-0.951057)*(\x-0.866025)*(\x-0.743145)*(\x-0.587785)*(\x-0.406737)*(\x-0.207912)*(\x-6.12323e-17)-47.5358*(\x-0.994522)*(\x-0.951057)*(\x-0.866025)*(\x-0.743145)*(\x-0.587785)*(\x-0.406737)*(\x-0.207912)*(\x-6.12323e-17)*(\x+0.207912)-140.628*(\x-0.994522)*(\x-0.951057)*(\x-0.866025)*(\x-0.743145)*(\x-0.587785)*(\x-0.406737)*(\x-0.207912)*(\x-6.12323e-17)*(\x+0.207912)*(\x+0.406737)-235.756*(\x-0.994522)*(\x-0.951057)*(\x-0.866025)*(\x-0.743145)*(\x-0.587785)*(\x-0.406737)*(\x-0.207912)*(\x-6.12323e-17)*(\x+0.207912)*(\x+0.406737)*(\x+0.587785)-302.208*(\x-0.994522)*(\x-0.951057)*(\x-0.866025)*(\x-0.743145)*(\x-0.587785)*(\x-0.406737)*(\x-0.207912)*(\x-6.12323e-17)*(\x+0.207912)*(\x+0.406737)*(\x+0.587785)*(\x+0.743145)-331.791*(\x-0.994522)*(\x-0.951057)*(\x-0.866025)*(\x-0.743145)*(\x-0.587785)*(\x-0.406737)*(\x-0.207912)*(\x-6.12323e-17)*(\x+0.207912)*(\x+0.406737)*(\x+0.587785)*(\x+0.743145)*(\x+0.866025)-333.619*(\x-0.994522)*(\x-0.951057)*(\x-0.866025)*(\x-0.743145)*(\x-0.587785)*(\x-0.406737)*(\x-0.207912)*(\x-6.12323e-17)*(\x+0.207912)*(\x+0.406737)*(\x+0.587785)*(\x+0.743145)*(\x+0.866025)*(\x+0.951057)};
    \addplot+[color=red!20!black!80,no marks]{0.0386906-0.0773136*(\x-0.996917)+0.120771*(\x-0.996917)*(\x-0.97237)-0.17893*(\x-0.996917)*(\x-0.97237)*(\x-0.92388)+0.271509*(\x-0.996917)*(\x-0.97237)*(\x-0.92388)*(\x-0.85264)-0.441458*(\x-0.996917)*(\x-0.97237)*(\x-0.92388)*(\x-0.85264)*(\x-0.760406)+0.785471*(\x-0.996917)*(\x-0.97237)*(\x-0.92388)*(\x-0.85264)*(\x-0.760406)*(\x-0.649448)-1.44565*(\x-0.996917)*(\x-0.97237)*(\x-0.92388)*(\x-0.85264)*(\x-0.760406)*(\x-0.649448)*(\x-0.522499)+1.11365*(\x-0.996917)*(\x-0.97237)*(\x-0.92388)*(\x-0.85264)*(\x-0.760406)*(\x-0.649448)*(\x-0.522499)*(\x-0.382683)+23.7955*(\x-0.996917)*(\x-0.97237)*(\x-0.92388)*(\x-0.85264)*(\x-0.760406)*(\x-0.649448)*(\x-0.522499)*(\x-0.382683)*(\x-0.233445)-24.128*(\x-0.996917)*(\x-0.97237)*(\x-0.92388)*(\x-0.85264)*(\x-0.760406)*(\x-0.649448)*(\x-0.522499)*(\x-0.382683)*(\x-0.233445)*(\x-0.0784591)-331.452*(\x-0.996917)*(\x-0.97237)*(\x-0.92388)*(\x-0.85264)*(\x-0.760406)*(\x-0.649448)*(\x-0.522499)*(\x-0.382683)*(\x-0.233445)*(\x-0.0784591)*(\x+0.0784591)-965.9*(\x-0.996917)*(\x-0.97237)*(\x-0.92388)*(\x-0.85264)*(\x-0.760406)*(\x-0.649448)*(\x-0.522499)*(\x-0.382683)*(\x-0.233445)*(\x-0.0784591)*(\x+0.0784591)*(\x+0.233445)-1734.36*(\x-0.996917)*(\x-0.97237)*(\x-0.92388)*(\x-0.85264)*(\x-0.760406)*(\x-0.649448)*(\x-0.522499)*(\x-0.382683)*(\x-0.233445)*(\x-0.0784591)*(\x+0.0784591)*(\x+0.233445)*(\x+0.382683)-2309.92*(\x-0.996917)*(\x-0.97237)*(\x-0.92388)*(\x-0.85264)*(\x-0.760406)*(\x-0.649448)*(\x-0.522499)*(\x-0.382683)*(\x-0.233445)*(\x-0.0784591)*(\x+0.0784591)*(\x+0.233445)*(\x+0.382683)*(\x+0.522499)-2462.38*(\x-0.996917)*(\x-0.97237)*(\x-0.92388)*(\x-0.85264)*(\x-0.760406)*(\x-0.649448)*(\x-0.522499)*(\x-0.382683)*(\x-0.233445)*(\x-0.0784591)*(\x+0.0784591)*(\x+0.233445)*(\x+0.382683)*(\x+0.522499)*(\x+0.649448)-2166.92*(\x-0.996917)*(\x-0.97237)*(\x-0.92388)*(\x-0.85264)*(\x-0.760406)*(\x-0.649448)*(\x-0.522499)*(\x-0.382683)*(\x-0.233445)*(\x-0.0784591)*(\x+0.0784591)*(\x+0.233445)*(\x+0.382683)*(\x+0.522499)*(\x+0.649448)*(\x+0.760406)-1552.44*(\x-0.996917)*(\x-0.97237)*(\x-0.92388)*(\x-0.85264)*(\x-0.760406)*(\x-0.649448)*(\x-0.522499)*(\x-0.382683)*(\x-0.233445)*(\x-0.0784591)*(\x+0.0784591)*(\x+0.233445)*(\x+0.382683)*(\x+0.522499)*(\x+0.649448)*(\x+0.760406)*(\x+0.85264)-788.326*(\x-0.996917)*(\x-0.97237)*(\x-0.92388)*(\x-0.85264)*(\x-0.760406)*(\x-0.649448)*(\x-0.522499)*(\x-0.382683)*(\x-0.233445)*(\x-0.0784591)*(\x+0.0784591)*(\x+0.233445)*(\x+0.382683)*(\x+0.522499)*(\x+0.649448)*(\x+0.760406)*(\x+0.85264)*(\x+0.92388)+3.59221e-12*(\x-0.996917)*(\x-0.97237)*(\x-0.92388)*(\x-0.85264)*(\x-0.760406)*(\x-0.649448)*(\x-0.522499)*(\x-0.382683)*(\x-0.233445)*(\x-0.0784591)*(\x+0.0784591)*(\x+0.233445)*(\x+0.382683)*(\x+0.522499)*(\x+0.649448)*(\x+0.760406)*(\x+0.85264)*(\x+0.92388)*(\x+0.97237)};
    \addplot+[color=black,thick,no marks]{1/(1+25*\x*\x)};
    \addlegendentry{$p_5(f;x)$}
    \addlegendentry{$p_{10}(f;x)$}
    \addlegendentry{$p_{15}(f;x)$}
    \addlegendentry{$p_{20}(f;x)$}
    \addlegendentry{$f(x)$}
    \end{axis}
  \end{tikzpicture}
\end{center}

This figure illustrates that the Chebyshev interpolation is free of the wide oscillations in assignment B.

\subsection{Assignment D}

Let $f(x)$ be the position at time $x$, then the vilocity at time $x$ is $f'(x)$.

Interpolating with the function values and deriviate values at $0,3,5,8,13$, we can get an polynomial of order $9$, as following.
\begin{align*}
  f(x)=&75x+7.16191x^{2}-10.0953x^{3}+5.50812x^{4}-1.5383x^{5}+0.243041x^{6}\\
  &-0.0218757x^{7}+0.00104059x^{8}-2.02236\times 10^{-5}x^{9}
\end{align*}

The image of the function sees the following figure.

\begin{center}
  \begin{tikzpicture}[global scale = 0.8]
    \begin{axis}[
        axis lines=middle,
        samples=51,
  %       grid,                
  %      thick,
        domain=0:13,
        legend pos=outer north east,
        smooth,
    ]
    \addplot+[color=black,thick,no marks]{0+75*\x+7.16191*\x*\x-10.0953*\x*\x*\x+5.50812*\x*\x*\x*\x-1.5383*\x*\x*\x*\x*\x+0.243041*\x*\x*\x*\x*\x*\x-0.0218757*\x*\x*\x*\x*\x*\x*\x+0.00104059*\x*\x*\x*\x*\x*\x*\x*\x-2.02236e-05*\x*\x*\x*\x*\x*\x*\x*\x*\x};
    \end{axis}
  \end{tikzpicture}
\end{center}

To get the vilocity image, we can calculate the deriviate of $f$, as following.
\begin{align*}
  f'(x)=&75+14.3238x-30.2859x^{2}+22.0325x^{3}-7.69148x^{4}+1.45825x^{5}\\
  &-0.15313x^{6}+0.00832472x^{7}-0.000182013x^{8}
\end{align*}

The image of vilocity function sees the following figure.

\begin{center}
  \begin{tikzpicture}[global scale = 0.8]
    \begin{axis}[
      axis lines=middle,
      samples=51,
    %       grid,                
    %      thick,
      domain=0:13,
      ymin=45,
      ymax=130,
      legend pos=outer north east,
      smooth,
    ]
    \addplot+[color=black,thick,no marks]{75+14.3238*\x-30.2859*\x*\x+22.0325*\x*\x*\x-7.69148*\x*\x*\x*\x+1.45825*\x*\x*\x*\x*\x-0.15313*\x*\x*\x*\x*\x*\x+0.00832472*\x*\x*\x*\x*\x*\x*\x-0.000182013*\x*\x*\x*\x*\x*\x*\x*\x};
    \end{axis}
  \end{tikzpicture}
\end{center}

Now we can answer the problems:

\begin{enumerate}[(a)]
  \item The position of time $t=10s$ is $f(10)=742.503\;(\text{feet})$.
  \item As the vilocity image shows, it could be easily observed that the vilocity around time $t=12s$ reaches about $120$ feet per second. That's an excessive speeding.
\end{enumerate}

\subsection{Assignment E}

Here are the interpolating results.
\begin{align*}
  p_\text{sp1}(x) =& 6.67+1.77167\pi_{1}(x)+0.457833\pi_{2}(x)-0.124778\pi_{3}(x)+0.013566\pi_{4}(x)\\
                   & -0.000978085\pi_{5}(x)+4.1477\times 10^{-5}\pi_{6}(x)\\
  p_\text{sp2}(x) =& 6.67+1.57167\pi_{1}(x)-0.0871667\pi_{2}(x)-0.0152729\pi_{3}(x)+0.00257908\pi_{4}(x)\\
                   & -0.000204804\pi_{5}(x)+8.6768\times 10^{-6}\pi_{6}(x)
\end{align*}

The images see the following figure.

\begin{center}
  \begin{tikzpicture}[global scale = 0.8]
    \begin{axis}[
      axis lines=middle,
      samples=51,
    %       grid,                
    %      thick,
      domain=0:30,
      ymin = -30,
      ymax = 48,
      legend pos=outer north east,
      smooth,
    ]
    \addplot+[thick,no marks]{6.67+1.77167*\x+0.457833*\x*(\x-6)-0.124778*\x*(\x-6)*(\x-10)+0.013566*\x*(\x-6)*(\x-10)*(\x-13)-0.000978085*\x*(\x-6)*(\x-10)*(\x-13)*(\x-17)+4.1477e-05*\x*(\x-6)*(\x-10)*(\x-13)*(\x-17)*(\x-20)};
    \addplot+[thick,no marks]{6.67+1.57167*\x-0.0871667*\x*(\x-6)-0.0152729*\x*(\x-6)*(\x-10)+0.00257908*\x*(\x-6)*(\x-10)*(\x-13)-0.000204804*\x*(\x-6)*(\x-10)*(\x-13)*(\x-17)+8.6768e-06*\x*(\x-6)*(\x-10)*(\x-13)*(\x-17)*(\x-20)};
    \addlegendentry{sp1}
    \addlegendentry{sp2}
    \end{axis}
  \end{tikzpicture}
\end{center}

In fact, that's not an acceptable result. Following the result below, the larvaes in sp1 died soon after birth, then reborned at about the 5th day. Morever, the larvaes will have eternal lives. The average weight after another 15 days is
\begin{align*}
  p_\text{sp1}(43) = 14640.3\\
  p_\text{sp2}(43) = 2981.48
\end{align*}

Amazing.

This problem shows that predicting the trend with high-order polynomial interpolation is ridiculous.

\section{Extension}

This pakage supports more data types rather than \verb|double|. For example, if you want to know the exact interpolation polynomial, which may be expressed with high-precision fractions. You could include the pakage \verb|fraction.h| first. And define a interpolation by:

\begin{lstlisting}
  T_HermiteInterpolation<fraction> poly1(x, sp1);
\end{lstlisting}

The detail sees example code \verb|test_Hermite_with_fraction.cpp|. The output is:

\begin{lstlisting}
  1+49/12x-155/36x^{2}+49/36x^{3}-5/36x^{4}
\end{lstlisting}

The computation speed is not very fast. That's because the fraction libery and the big-integer libery it depends are naive implementations without any optimization. But it does help to seeing the exact interpolation polynomials. In other words, I can calculate my theretical homeworks with this.

Actually, you could modify \verb|fraction| to any other fields, such as $\mathbb{Z}_p$ and $\mathbb{C}$. Define a field class and provide basic operations, then you could use the interpolation in your field.

\section{Summary}

The figures in this report are drawn with \textbf{Tikz}.

This template is designed by Elegant\LaTeX{} Program.

Many appreciations for your carefully reading. If you found any mistakes, please contact me directly. Have fun with your loving one (boyfriend, girlfriend or coding)!

\end{document}
